
var randomStrFunc = function(len) {
　　len = len || 16;
　　var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
　　var maxPos = $chars.length;
　　var pwd = '';
　　for (i = 0; i < len; i++) {
　　　　pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
　　}
　　return pwd;
};

var wxApiInit = function() {
	var noncestr = randomStrFunc(16);
	var timestamp = parseInt(new Date().getTime() / 1000);
	var url = window.location.href;
	url = url.replace(window.location.hash, "");
	$.ajax({
		url: base + '/common/weixin/jsapiSignature.jhtml',
		data: {noncestr: noncestr, timestamp: timestamp, url: url},
		async: false,
		dataType: 'json',
		error: function() {
			alert("reqerror");
		},
		success: function(dd) {
			wx.config({
	    	    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
	    	    appId: 'wx1f8e6c3c87945e87', // 必填，公众号的唯一标识
	    	    timestamp: timestamp, // 必填，生成签名的时间戳
	    	    nonceStr: noncestr, // 必填，生成签名的随机串
	    	    signature: dd.data,// 必填，签名，见附录1
	    	    jsApiList: [
	                'checkJsApi',
	                'onMenuShareTimeline',
	                'onMenuShareAppMessage',
	                'onMenuShareQQ',
	                'onMenuShareWeibo',
	                'hideMenuItems',
	                'showMenuItems',
	                'hideAllNonBaseMenuItem',
	                'showAllNonBaseMenuItem',
	                'translateVoice',
	                'startRecord',
	                'stopRecord',
	                'onRecordEnd',
	                'playVoice',
	                'pauseVoice',
	                'stopVoice',
	                'uploadVoice',
	                'downloadVoice',
	                'chooseImage',
	                'previewImage',
	                'uploadImage',
	                'downloadImage',
	                'getNetworkType',
	                'openLocation',
	                'getLocation',
	                'hideOptionMenu',
	                'showOptionMenu',
	                'closeWindow',
	                'scanQRCode',
	                'chooseWXPay',
	                'openProductSpecificView',
	                'addCard',
	                'chooseCard',
	                'openCard'
	              ]
	    	});
			
			wx.error(function(res){
	        	alert(res);
	        });
		}
	});
};

    				